import 'package:flutter/material.dart';

class TabPage extends StatefulWidget {
  final String title;
  const TabPage({Key? key, required this.title}) : super(key: key);

  @override
  _TabPageState createState() => _TabPageState();
}

//重写keepAlive 为ture ，就是可以有记忆功能了。
class _TabPageState extends State<TabPage> with AutomaticKeepAliveClientMixin {

  int _count = 0;

  //重写keepAlive 为ture ，就是可以有记忆功能了。
  @override
  bool get wantKeepAlive => true;

  void _incrementCounter() {
    setState(() {
      _count++;
    });
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('点击一下加1'),
            Text('${widget.title} $_count 辆')
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: '点我',
        child: Icon(Icons.add),
      ),
    );
  }
}
